package com.woniu.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.common.dto.OrderBreakDto;
import com.woniu.common.utils.PageParam;
import com.woniu.common.utils.ResponseData;
import com.woniu.order.dto.LogisticsDto;
import com.woniu.order.pojo.Logistics;
import com.woniu.order.pojo.LogisticsCompany;
import com.woniu.order.pojo.OrderDetail;
import com.woniu.order.pojo.ZyOrder;
import com.woniu.order.service.LogisticsCompanyService;
import com.woniu.order.service.LogisticsService;
import com.woniu.order.mapper.LogisticsMapper;
import com.woniu.order.service.OrderDetailService;
import com.woniu.order.service.ZyOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xue
 * @description 针对表【logistics(物流表)】的数据库操作Service实现
 * @createDate 2024-08-10 09:44:19
 */
@Service
public class LogisticsServiceImpl extends ServiceImpl<LogisticsMapper, Logistics>
        implements LogisticsService {


    @Autowired
    private LogisticsCompanyService logisticsCompanyService;
    @Autowired
    private ZyOrderService zyOrderService;
    @Autowired
    private OrderDetailService orderDetailService;
    @Autowired
    private LogisticsMapper logisticsMapper;
    @Override
    public ResponseData<?> AddDeliverGoods(LogisticsDto params) {
        Logistics logistics = new Logistics();
        logistics.setId(params.getLogisticsId());
        logistics.setLogisticsCompanyId(params.getLogisticsCompanyId());
        LogisticsCompany logisticsCompany = logisticsCompanyService.lambdaQuery().eq(LogisticsCompany::getId, params.getLogisticsCompanyId())
                .one();
        logistics.setLogisticsCompanyName(logisticsCompany.getLogisticsCompanyName());
        logistics.setLogisticsStatus(0);
        logistics.setFromWhere("119.912165, 31.874567");
        logistics.setToWhere(params.getAddrDto().getLongitude() +","+params.getAddrDto().getLatitude());
        save(logistics);
        //修改订单信息
        zyOrderService.lambdaUpdate().eq(ZyOrder::getId,params.getOrderId())
                .set(ZyOrder::getState,3)
                .update();
        //修改订单详情
        orderDetailService.lambdaUpdate().eq(OrderDetail::getOrderId,params.getOrderId())
                .set(OrderDetail::getState,3)
                .update();
        return new ResponseData<>().success();
    }

    @Override
    public ResponseData<?> queryWuliuAll(PageParam<?> param) {
        PageHelper.startPage(param.getPageNum(),param.getPageSize());
        List<Logistics> orderBreakDtos = logisticsMapper.queryWuliuAll(param.getParam());
        PageInfo objectPageInfo = new PageInfo<>(orderBreakDtos);
        return new ResponseData().success(objectPageInfo);
    }
}




